/**
 * Definition for singly-linked list.
 * struct ListNode {
 *     int val;
 *     struct ListNode *next;
 * };
 */


struct ListNode* swapNodes(struct ListNode* head, int k){
    struct ListNode* ss = head;
    struct ListNode* sp = head;
    struct ListNode* sl = head;
    int i;
    for(i = 0 ; i <= 100000 ; i++){
        if(ss == NULL){
            break;
        }
        ss = ss->next;
    }
    int tmp = 0;
    int sz = i;
    int xz = k ;
    int cz = sz - k + 1;
    if(sz == 1){
        return head;
    }
    if(sz == 2){
        tmp = sp->val;
        sp->val = sp->next->val;
        sp = sp->next;
        sp->val = tmp;
        return head;
    }
    if(xz == cz){
        return head;
    }
    for(i = 1 ; i <= sz ; i++){
        if(i == cz){
            break;
        }
        sp = sp->next;
    }
    for(i = 1 ; i <= sz ; i++){
        if(i == xz){
            break;

         sl = sl->next;
    }
    tmp = sp->val;
    sp->val = sl->val;
    sl->val = tmp;

    return head;
}
